package com.example.xinyun.provider;

import com.example.xinyun.ResourceTable;
import com.example.xinyun.db.xinliList;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.*;

import java.util.ArrayList;
import java.util.List;


public class PsychologicalProvider extends BaseItemProvider {
    List<xinliList> xinliLists=new ArrayList();
    private AbilitySlice abilitySlice;

    public PsychologicalProvider(List<xinliList> xinliLists, AbilitySlice abilitySlice) {
        this.xinliLists = xinliLists;
        this.abilitySlice = abilitySlice;
    }


    @Override
    public int getCount() {
        return xinliLists==null?0:xinliLists.size();
    }

    @Override
    public Object getItem(int i) {
        if (xinliLists!=null && i>=0 && i<xinliLists.size()){
            return xinliLists.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        final Component cpt;
        if(component==null){
            cpt = LayoutScatter.getInstance(this.abilitySlice).parse(ResourceTable.Layout_psychological_list, null, false);
        }
        else
        {
            cpt = component;
        }

        xinliList xinli = this.xinliLists.get(i);
        //设置ListContainer对象中每个控件的内容
        Text text = (Text) cpt.findComponentById(ResourceTable.Id_text_xinli);
        text.setText(xinli.getText());
        Text yuedu = (Text) cpt.findComponentById(ResourceTable.Id_yuedu_psy);
        yuedu.setText(xinli.getNumberCanyu()+"参与");
        Image image=(Image) cpt.findComponentById(ResourceTable.Id_image_xinli);
        image.setPixelMap(ResourceTable.Media_wenjuanxing);
        image.setCornerRadius(30f);
        return cpt;
    }
}
